package com.bawei.a2010douyin.ui.xihuan;

import com.bawei.a2010douyin.base.mvp.BasePresenter;
import com.bawei.a2010douyin.base.rx.BaseFunc;
import com.bawei.a2010douyin.entity.VideoEntity;

import java.util.List;

import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;

public class XiHuanPresenter extends BasePresenter<XiHuanContract.IXiHuanView> implements XiHuanContract.IXiHuanPresenter {
    private XiHuanContract.IXiHuanModel mIXiHuanModel;
    public XiHuanPresenter() {
        mIXiHuanModel = new XiHuanModel();
    }


    @Override
    public void getDianZanvideos() {
        mIXiHuanModel.getDianZanvideos()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .flatMap(new BaseFunc<List<VideoEntity>>())
                .subscribe(new Observer<List<VideoEntity>>() {
                    @Override
                    public void onSubscribe(Disposable d) {
                        mCompositeDisposable.add(d);
                    }

                    @Override
                    public void onNext(List<VideoEntity> videoEntities) {
                        if(isAttach()){
                            getView().showDianzan(videoEntities);
                        }
                    }

                    @Override
                    public void onError(Throwable e) {
                        if(isAttach()){
                            getView().onError();
                        }
                    }

                    @Override
                    public void onComplete() {

                    }
                });

    }
}
